package poiTests;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import junit.framework.TestCase;

import org.junit.BeforeClass;
import org.junit.Test;

import exceptions.WrongIDException;

import poi.POISearcher;

/**
 * @author pdudnyt
 *
 */
public class POISearcherTest extends TestCase {

	private POISearcher pSearch;
	/**
	 * @throws java.lang.Exception
	 */
	@BeforeClass
	public final void setUp() {
	
	}

	public void tearDown() {
	}
	/**
	 * Test method for {@link poi.POISearcher#search()}.
	 */
	@Test
	public final void testSearch() {
		pSearch = new POISearcher(null);
		pSearch.setHomePointID(16);
		pSearch.setSearchName("ta");
		pSearch.setSearchType("Food");
		pSearch.setSearchDistance(5);
		try {
			pSearch.search();
		} catch (WrongIDException e) {
			fail("Can't find home recrd!");
		}
		assertEquals(pSearch.getSearchResult().size(), 1);

		pSearch.setSearchName("blabla");
		pSearch.setSearchType("My");
		pSearch.setSearchDistance(50);
		try {
			pSearch.search();
		} catch (WrongIDException e) {
			fail("Can't find home recrd!");
		}
		assertEquals(pSearch.getSearchResult().size(), 0);

		pSearch.setSearchName("");
		pSearch.setSearchType("My");
		pSearch.setSearchDistance(50);
		try {
			pSearch.search();
		} catch (WrongIDException e) {
			fail("Can't find home recrd!");
		}
		assertEquals(pSearch.getSearchResult().size(), 4);
		pSearch.setSearchName("");
		pSearch.setSearchType("Recreation");
		pSearch.setSearchDistance(3);
		try {
			pSearch.search();
		} catch (WrongIDException e) {
			fail("Can't find home recrd!");
		}
		assertEquals(pSearch.getSearchResult().size(), 1);
		pSearch.setSearchName("");
		pSearch.setSearchType("Recreation");
		pSearch.setSearchDistance(4);
		try {
			pSearch.search();
		} catch (WrongIDException e) {
			fail("Can't find home recrd!");
		}
		assertEquals(pSearch.getSearchResult().size(),2);
	}

}
